<?php
header('Content-Encoding: plain');
include_once './config.php';
$url = $_REQUEST['url'];
$paths = parse_url($url);
if ($paths['scheme'] && $paths['path']) {
    $url = base64_encode($url);
} elseif ($paths['path']) {
    $url = base64_encode('http://' . $url);
}
unset($paths);
$strsql = 'SELECT id FROM `' . $url_tab . '` WHERE `url` like "' . $url . '"';
$result = mysql_db_query($mysql_database, $strsql, $db);
$row = mysql_fetch_row($result);
if ($row) {
    $id = $row['0'];
} else {
    $strsql = 'INSERT INTO `' . $url_tab . '`(`url`) VALUE ("' . $url . '")';
    $result = mysql_db_query($mysql_database, $strsql, $db);
    if ($result) {
        $id = mysql_insert_id();
    }
}
unset($db, $row, $result);
$id = dec2any($id);
if (isset($_REQUEST['ajax'])) {
	echo isset($_REQUEST['callback'])?$_REQUEST['callback'].'("'.$id.'")':json_encode($id);
} else {
    echo 'link:<a href="http://url.xunlitao.com/' . $id . '">url.xunlitao.com/' . $id . '</a>';
}
?>
